//
//  GoodManagerViewController.m
//  SafeFoodManagerDemo
//
//  Created by bob on 2017/10/26.
//  Copyright © 2017年 bob. All rights reserved.
//

#import "GoodManagerViewController.h"
#import "JobListModel.h"
#import "HomeFunTableViewCell.h"
#import "GoodLsitViewController.h"
#import "GoodCataViewController.h"
#import "SafeFoodManagerDemo-Bridging-Header.h"
#import "SafeFoodManagerDemo-Swift.h"
@interface GoodManagerViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)TB_TableView *homeTableView;

@end

@implementation GoodManagerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
     [self.view addSubview:self.homeTableView];
    // Do any additional setup after loading the view.
}

-(TB_TableView*)homeTableView
{
    if (!_homeTableView) {
        
        _homeTableView=[[TB_TableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64) style:UITableViewStylePlain];
        
        _homeTableView.delegate=self;
        
        _homeTableView.dataSource=self;
        
        _homeTableView.tableFooterView=[[UIView alloc]init];
        
        [_homeTableView registerNib:[UINib nibWithNibName:@"HomeFunTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    }
    return _homeTableView;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    return 2;
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return 1;
    
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomeFunTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    if (indexPath.section==0) {
        
        cell.IcoImageView.image=[UIImage imageNamed:@"peopleManage"];
        
        cell.TitleLabel.text=@"商品列表";
        
    }else{
        
        cell.IcoImageView.image=[UIImage imageNamed:@"PeopleWork"];
        
        cell.TitleLabel.text=@"商品分类";
        
    }
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 60;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 20;
    
}


-(void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section
{
    
    view.tintColor=TBColorTableViewBg;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        
        JobListModel *list=[JobListModel new];
        
        GoodLsitViewController *GoodLsit=[GoodLsitViewController new];
        
        if ([self getUserType]==1) {
            
            GoodLsit.isEdit=YES;
            
            GoodLsit.isdeleMore=YES;
            
            list.shopId=[LoginStatuesModel shopId];
            
            
        }else{
            
            GoodLsit.isEdit=NO;
            GoodLsit.isdeleMore=YES;
            
            if (self.shopid!=0) {
                list.shopId=self.shopid;
                GoodLsit.isEdit=YES;
                GoodLsit.AddBtnTitle = @"新增商品";
            }
            
            if ([self getUserType]==3) {
                
                list.marketId=[LoginStatuesModel getStaffId];
            }
            
        }
        
        GoodLsit.Reqmodel=list;
        GoodLsit.shopId = list.shopId;
        GoodLsit.searchName=@"输入商品名称";
        GoodLsit.AddBtnTitle=@"新增商品";
        
        GoodLsit.title=@"商品列表";
     
        [self.navigationController pushViewController:GoodLsit animated:YES];
        
    }else{
        
        JobListModel *list=[JobListModel new];
        
        GoodCataViewController *GoodCata=[GoodCataViewController new];
        
        if ([self getUserType]==1) {
            
            GoodCata.isEdit=YES;
            
            GoodCata.isdeleMore=YES;
            
            list.shopId=[LoginStatuesModel shopId];
            
        }else if([self getUserType]==2){
            GoodCata.isEdit=NO;
            
            GoodCata.isdeleMore=YES;
            
            if (self.shopid != 0) {
                GoodCata.isEdit  = YES;
            }
            list.shopId= self.shopid;
            
            
        }else{
            
            GoodCata.isEdit=NO;
            
            GoodCata.isdeleMore=NO;
            
            if (self.shopid!=0) {
                
                list.shopId=self.shopid;
                
            }
            
            if ([self getUserType]==3) {
                
                list.marketId=[LoginStatuesModel getStaffId];
            }
            
        }
        
        GoodCata.searchName=@"输入分类名称";
        GoodCata.AddBtnTitle=@"新增分类";
        GoodCata.Reqmodel=list;
        
        GoodCata.title=@"分类列表";
     
        [self.navigationController pushViewController:GoodCata animated:YES];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


@end
